package org.chengn.level_easy.context2085;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: Context2085
 * @Author ChengN
 * @Package org.chengn.level_easy.context2085
 * @Date 2024/1/12 0:33
 * @description: 统计出现过一次的公共字符串
 */
public class Context2085 {
    public int countWords(String[] words1, String[] words2) {
        Map<String, Integer> map = new HashMap<>();

        for (String word1 : words1) {
            map.put(word1, map.getOrDefault(word1, 0) + 1);
        }

        Map<String, Integer> map2 = new HashMap<>();
        for (String word2 : words2) {
            map2.put(word2, map2.getOrDefault(word2, 0) + 1);
        }

        int res = 0;
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if (entry.getValue() == 1) {
                Integer i = map2.get(entry.getKey());
                if (i != null && i == 1) {
                    res ++;
                }
            }
        }
        return res;

    }
}
